package com.baige.api.app.controller;

import com.baige.api.app.sdk.request.CouponGoodsListRequest;
import com.baige.api.app.sdk.request.CouponListRequest;
import com.baige.api.app.sdk.request.CouponUsableListRequest;
import com.baige.api.app.sdk.response.CouponResponse;
import com.baige.api.app.sdk.response.GoodsResponse;
import com.baige.common.core.BaseResponse;
import com.baige.common.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 用户优惠卷接口
 * @author wulg
 * @date 2018/12/13.
 */
@Api(value = "UserCouponController", description = "用户优惠卷接口", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/api/rest/user/coupon")
public class UserCouponController
{
    private static final Logger logger = LoggerFactory.getLogger(UserCouponController.class);


    /**
     * 用户可用的优惠卷列表
     *
     * @param userId        用户id
     * @param requestParams 请求参数
     * @return Result<List<CouponResponse>>
     */
    @GetMapping(value = "/v1/{userId}/usable", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户可用的优惠卷列表", notes = "用户可用的优惠卷列表", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<List<CouponResponse>> getUsableCouponList(@PathVariable("userId") String userId, @ModelAttribute("requestParams") @Valid CouponUsableListRequest requestParams) {
        return null;
    }

    /**
     * 用户优惠卷列表
     *
     * @param userId            用户id
     * @param requestParams     请求参数
     * @param bindingResult     参数校验
     * @return Result<List<CouponResponse>>
     */
    @GetMapping(value = "/v1/{userId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "用户优惠卷列表", notes = "用户优惠卷列表", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<List<CouponResponse>> getUserCouponList(@PathVariable("userId") String userId, @ModelAttribute("requestParams") @Valid CouponListRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("用户优惠卷列表参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }

    /**
     * 获取该优惠卷可用的商品列表
     *
     * @param couponId      优惠卷id
     * @param requestParams 请求参数
     * @param bindingResult 参数校验
     * @return Result<List<GoodsResponse>>
     */
    @GetMapping(value = "/v1/goods/{couponId}", produces = {"application/json;charset=UTF-8", "application/xml;charset=UTF-8"})
    @ApiOperation(value = "获取该优惠卷可用的商品列表", notes = "获取该优惠卷可用的商品列表", httpMethod = "GET", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
    public Result<List<GoodsResponse>> getProductListByCouponId(@PathVariable("couponId") String couponId, @Valid @ModelAttribute CouponGoodsListRequest requestParams, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.error("获取该优惠卷可用的商品列表参数传递错误,message:{}", bindingResult.getFieldErrors().get(0).getDefaultMessage());
            return BaseResponse.newErrorParamReturnObject(bindingResult.getFieldErrors().get(0).getDefaultMessage());
        }
        return null;
    }
}
